/*
 * CanvasFrame.java
 * 
 * Created by demory on Nov 21, 2009, 8:40:23 PM
 * 
 * Copyright 2008 David D. Emory
 * 
 * This file is part of Five Points. See <http://www.fpdev.org> for
 * additional information regarding the project.
 * 
 * Five Points is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Five Points is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Five Points.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.fpdev.apps.cart.gui;

import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import javax.swing.JInternalFrame;
import javax.swing.event.InternalFrameAdapter;
import javax.swing.event.InternalFrameEvent;
import org.fpdev.apps.cart.CartEventProcessor;
import org.fpdev.apps.cart.Editor;
import org.fpdev.apps.cart.gui.map.Canvas;

/**
 *
 * @author demory
 */
public class EditorFrame extends JInternalFrame {

  private Canvas canvas_;
  private Editor ed_;
  private CartGUI gui_;

  public EditorFrame(CartEventProcessor cep, Editor ed, CartGUI gui, String title) {
    super(title, true, true, true, true);
    canvas_ = new Canvas(cep, ed, gui);
    ed_ = ed;
    gui_ = gui;
    
    ed.setFrame(this);
    canvas_.addComponentListener(new ComponentAdapter() {
      @Override
      public void componentResized(ComponentEvent e) {
        //System.out.println("map resized");
        canvas_.resized();
      }
    });

    this.addInternalFrameListener(new InternalFrameAdapter() {
      @Override
      public void internalFrameActivated(InternalFrameEvent e) {
        gui_.setActiveEditorFrame(EditorFrame.this);
        gui_.updateUndoRedo(ed_);
      }

      @Override
      public void internalFrameClosed(InternalFrameEvent e) {
        gui_.editorFrameClosed();
      }
    });
    this.add(canvas_);
    gui.editorFrameOpened();
  }

  public Editor getEditor() {
    return ed_;
  }

  public Canvas getCanvas() {
    return canvas_;
  }
}
